main() {
  var dataSource = MyDataSource<int>();
  dataSource.pushData(100);
  dataSource.pushData(200);
  dataSource.pushData(300);
  print(dataSource.totalCount());
  print(dataSource.getData(0));
  print(dataSource.getData(1));
  print(dataSource.getData(2));
  var dataSource2 = MyDataSource<String>();
  dataSource2.pushData('hello');
  dataSource2.pushData('world');
  dataSource2.pushData('dart');
  print(dataSource2.totalCount());
  print(dataSource2.getData(0));
  print(dataSource2.getData(1));
  print(dataSource2.getData(2));


}

abstract class IDataSource {
  int totalCount();
  dynamic getData(int index);
}

// 泛型类
class MyDataSource<T> implements IDataSource {
  List<T> _dataArray = [];

  @override
  T getData(int index) {
    return _dataArray[index];
  }

  @override
  int totalCount() {
    return _dataArray.length;
  }

  void pushData(T data) {
    _dataArray.add(data);
  }
}
